Step 1 - Create project with C++ application and print to debug console

In this step you first create a new Kanzi Studio project with C++ application, and then add the code to the C++ application to print Hello world! to the Kanzi debug console.

To create a project with C++ application and print to Kanzi debug console:

  1. In Kanzi Studio Quick Start window click New Project...:
    1. Choose the name and location for your project.
      For example, name your project Hello world.
    2. In Project Type select Kanzi Studio project with C++ application.

    Kanzi creates a Kanzi Studio project in <KanziWorkspace>/Projects/<ProjectName>/Tool_project directory and the structure for the Visual Studio solution for your project in <KanziWorkspace>/Projects/<ProjectName>/Application:

  2. In Kanzi Studio select File > Export KZB > Export KZB Binary.
    Kanzi Studio creates the .kzb binary and configuration files from your Kanzi Studio project. Kanzi Studio stores the exported files in <KanziWorkspace>/Projects/<ProjectName>/Application/bin or the location you specify in the Binary Export Directory property in Project > Properties. The .kzb binary file contains all nodes and resources from your Kanzi Studio project, except the resources you mark in a localization table as locale packs.
    When you run your Kanzi application from Visual Studio, your Visual Studio solution reads these files to create your Kanzi application.
  3. In Visual Studio open the Visual Studio solution for your application located in <ProjectName>/Application/configs/platforms/win32.
    For example, if you named your Kanzi Studio project Hello world, the Visual Studio solution is called Hello_world.sln.
    Tip To open the directory of a Kanzi Studio project from Kanzi Studio, select File > Open in Windows Explorer.
  4. In Visual Studio in the Solution Explorer right-click the Hello_world project and select Set as StartUp Project.
  5. In Visual Studio open the hello_world.cpp file and include the kzs_log.h header.
    // System logging
    #include <system/debug/kzs_log.h>

    kzs_log.h header contains the functions that define the functionality for writing to Kanzi debug console.
  6. When you place a function inside the onProjectLoaded()Kanzi calls the function after it loads your application.
    virtual void onProjectLoaded() KZ_OVERRIDE
    {
    	// Prints Hello world! to the Kanzi debug console.
    	kzsLog(KZS_LOG_LEVEL_INFO, "Hello world!");
    }
  7. In Visual Studio select one of the solution configurations for your version of Visual Studio and run your application.
    For example, if you are still developing your application, select the GL_vs2010_Debug configuration. If you want to create a production version of your Kanzi application, select one of the available release configurations.

    Function kzsLog prints Hello world! to the Kanzi debug console.

    When in the debug mode, along with the Kanzi debug console, your Kanzi application is shown in the Kanzi player. Since by default a new Kanzi Studio project contains only a scene with a camera and a directional light, your application, shows an empty scene.

This is what your hello_world.cpp looks like when you complete this step.

#include <kanzi/kanzi.hpp>
// System logging
#include <system/debug/kzs_log.h>

using namespace kanzi;

class HelloWorld: public ExampleApplication
{
public:

	virtual void onConfigure(ApplicationProperties& configuration) KZ_OVERRIDE
	{
		configuration.binaryName = "Hello_world.kzb.cfg";
	}

	virtual void onProjectLoaded() KZ_OVERRIDE
	{
		// Prints Hello world! to the Kanzi debug console.
		kzsLog(KZS_LOG_LEVEL_INFO, "Hello world!");
	}
};

Application* createApplication()
{
	return new HelloWorld;
}

< PREVIOUS STEP

NEXT STEP >

See also

API reference